package 在cn.itcast.quartz.job;

import cn.itcast.quartz.demo.HelloJob;
import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

/**
 * Created by Think on 2017/9/26.
 */
public class Demo3Cron {

    public static void main(String[] args) throws SchedulerException {
        // 定时器对象
        Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();

        // 定义一个工作对象
        JobDetail job = JobBuilder.newJob(HelloJob.class)
                .withIdentity("job1", "group1")
                .build();
        // 定义触发器
        Trigger trigger = TriggerBuilder.newTrigger()
                .withIdentity("trigger1", "group1")
                .withSchedule(CronScheduleBuilder.cronSchedule("* 24 22 * * ?"))//每天16:37开始执行，没一秒执行一次，16:38不再执行
                .build();

        scheduler.scheduleJob(job, trigger);
        // 开启定时任务
        scheduler.start();
    }

}
